package com.example.service;

import cn.hutool.core.date.DateTime;
import com.example.entity.PatientVisit;
import com.example.mapper.PatientVisitMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 就诊记录表业务处理
 **/
@Service
public class PatientVisitService {

    @Resource
    private PatientVisitMapper patientVisitMapper;

    /**
     * 新增
     */
    public void add(PatientVisit patientVisit) {
        patientVisitMapper.insert(patientVisit);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        patientVisitMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            patientVisitMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(PatientVisit patientVisit) {
        patientVisitMapper.updateById(patientVisit);
    }

    /**
     * 根据ID查询
     */
    public PatientVisit selectById(Integer id) {
        return patientVisitMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<PatientVisit> selectAll(PatientVisit patientVisit) {
        return patientVisitMapper.selectAll(patientVisit);
    }

    /**
     * 分页查询
     */
    public PageInfo<PatientVisit> selectPage(PatientVisit patientVisit, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PatientVisit> list = patientVisitMapper.selectAll(patientVisit);
        System.out.println(list);
        return PageInfo.of(list);
    }

    public void updateEndTime(PatientVisit patientVisit) {
        patientVisit.setEndTime(String.valueOf(DateTime.now()));
        patientVisitMapper.updateById(patientVisit);
    }

    public void updateHospitalizedStatus(PatientVisit patientVisit) {
        patientVisitMapper.updateHospitalizedStatus(patientVisit);
    }
}